package com.kuaiying.kuai.ying.controller.user;

import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.kuaiying.kuai.ying.model.user.UserModel;
import com.kuaiying.kuai.ying.validator.LoginValidator;

public class UserController extends Controller{

	public void index(){
		render("login.html");
	}
	@Before( LoginValidator.class )
	public void login(){
		render("login.html");
		String userName = getPara("uname");
    	String pwd = getPara("password");
    	System.out.println( userName );
    	UserModel user = UserModel.me.getUserByNameAndPwd(userName, pwd);
    	
    	if (user != null){
            String bbsID = userName + pwd;
            setCookie("bbsID", bbsID, 3600*24*30);
            setSessionAttr("username", userName);
            setSessionAttr("userID", user.get("user_id"));
            redirect("/");
        }else{
            setAttr("msg", "用户名或密码错误");
            render("/user/login.html");
        }
	}
}
